package com.bw.day03.adapter

import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.bw.base.net.entity.Order
import com.bw.base.net.entity.OrderInfo
import com.bw.day03.R
import com.bw.day03.util.GlideUtlis
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class OrderAdapter: BaseQuickAdapter<Order, BaseViewHolder>(R.layout.item_order) {
    override fun convert(
        holder: BaseViewHolder,
        item: Order
    ) {
        holder.setText(R.id.order_time,item.createTime)
        holder.setText(R.id.order_status,item.orderStatus)
        holder.setText(R.id.order_total,"共${item.totalNum}种商品,合计金额${item.payPrice}元")
        val view = holder.getView<RecyclerView>(R.id.order_rv)
        val orderChildAdapter = OrderChildAdapter()
        orderChildAdapter.data.addAll(item.orderInfoList)
        view.adapter = orderChildAdapter
        view.layoutManager= LinearLayoutManager(context)
        if (item.orderStatus=="待支付"){
            holder.getView<TextView>(R.id.order_pay).text="立即付款"
            holder.getView<TextView>(R.id.order_cancel).text="取消订单"
        }else if (item.orderStatus=="待发货"){
            holder.getView<TextView>(R.id.order_pay).text="催发货"
            holder.getView<TextView>(R.id.order_cancel).text="申请售后"
        }else if (item.orderStatus=="售后"){
            holder.getView<TextView>(R.id.order_pay).text="查看进度"
            holder.getView<TextView>(R.id.order_cancel).text="再次购买"
        }

    }
}
class OrderChildAdapter: BaseQuickAdapter<OrderInfo, BaseViewHolder>(R.layout.item_order_child){
    override fun convert(
        holder: BaseViewHolder,
        item: OrderInfo
    ) {
        GlideUtlis.loadNormal(context,item.image,holder.getView(R.id.preoder_iv))
        holder.setText(R.id.preoder_storename,item.storeName)
        holder.setText(R.id.preorder_num,item.cartNum.toString())
        holder.setText(R.id.preorder_price,"¥"+item.price)
        holder.setText(R.id.preorder_sku,"")
    }

}